<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>原型式继承</title>
	</head>
	<body>
		<script>
            //方法等同于Object.create()
            //返回原来的原型对象
			function object(obj) {
				function F() {}
				F.prototype = obj
				return new F()
			}


            //利用一个空对象作为中介，将某个对象直接赋值给空对象构造函数的原型。
			var person = {
				name: 'Nicholas',
				friends: ['Shelby', 'Court', 'Van'],
			}

			var anotherPerson = object(person)
			anotherPerson.name = 'Greg'
			anotherPerson.friends.push('Rob')

			var yetAnotherPerson = object(person)
			yetAnotherPerson.name = 'Linda'
			yetAnotherPerson.friends.push('Barbie')

            
    //原型链继承多个实例的引用类型属性指向相同，存在篡改的可能。
   // 无法传递参数


			console.log(person.friends) //"Shelby,Court,Van,Rob,Barbie"
		</script>
	</body>
</html>
